package com.mvd.app.adapter;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;

/**
 * @ProjectName: PDA_An_2020
 * @Package: com.mvd.app.api
 * @ClassName: MyTypeAdapterFactory
 * @Description: java类作用描述
 * @Author: liuxj
 * @CreateDate: 2023-03-09 10:24
 * @UpdateUser: 更新者
 * @UpdateDate: 2023-03-09 10:24
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class MyTypeAdapterFactory implements TypeAdapterFactory {
    public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {

        Class<T> rawType = (Class<T>) type.getRawType();
        if (rawType == String.class)
            return (TypeAdapter<T>) new StringAdapter();
        if (rawType == int.class)
            return (TypeAdapter<T>) new IntegerAdapter();
//        if (rawType == boolean.class)
//            return (TypeAdapter<T>)new BooleanAdapter();
//        if (rawType == double.class)
//            return (TypeAdapter<T>)new DoubleAdapter();
//        if (rawType == float.class)
//            return (TypeAdapter<T>)new FloatAdapter();
        return null;
    }
}
